/**
 * 找出一个int型数组中符合特定条件的元素，打印之；特定条件如（不限于）：
 * 1. 数组元素比n小；
 * 2. 数组元素比n大；
 * 3. 数组元素等于n
 *   
*/

#include <iostream>
#include <cstdlib>

using namespace std;

#define ARRAY_SIZE 10

typedef void (*fp)(int, int *, int);

void show_array_max(int base, int *array, int len)
{
    for (int i = 0; i < len; ++i)
    {
        if (array[i] > base)
        {
            cout << array[i] << " ";
        }
    }

    cout << endl;
}

void show_array_min(int base, int *array, int len)
{
    for (int i = 0; i < len; ++i)
    {
        if (array[i] < base)
        {
            cout << array[i] << " ";
        }
    }

    cout << endl;
}

void show_array_equal(int base, int *array, int len)
{
    for (int i = 0; i < len; ++i)
    {
        if (array[i] == base)
        {
            cout << array[i] << " ";
        }
    }

    cout << endl;
}

void show_array(int base, int *array, int len, fp func)
{
    func(base, array, len);
}

int main()
{

    int array[ARRAY_SIZE];

    for (int i = 0; i < ARRAY_SIZE; ++i)
    {
        array[i] = rand() % 10;
    }

    cout << "Show Array Data:\n";
    for (int i = 0; i < ARRAY_SIZE; ++i)
    {
        cout << "\t" << array[i];
    }
    cout << "\n";

    show_array(5, array, ARRAY_SIZE, show_array_max);
    show_array(5, array, ARRAY_SIZE, show_array_min);
    show_array(5, array, ARRAY_SIZE, show_array_equal);

    return 0;
}